<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : area.class.php   FILE_PATH : \\classes\application\shop_pay.class.php
 * ....关于店铺缴费
 *
 * @copyright workflow_system
 * @author workflow Develop Team 
 * @package
 * @subpackage
 * @version Tue Jun 29 15:02:45 CST 2008
 */

class shopPayClass extends FrameWork {
	/**
	 * 模式列表
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function listShopMode($condition,&$obj_page){
		$conditionstr = $this->_conditionSearchMode($condition);
		$mode_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "shop_pay_mode");
		return $mode_array;
	}
	
	/**
	 * 构造检索条件
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function _conditionSearchMode($condition){
		$condition_str = "";
		//模糊搜索缴费条目名称
		if ($condition['like_mode_name'] != ''){
			$condition_str .= " and mode_name like '%" . $condition['like_mode_name'] . "%'";
		}
		//缴费条目类别
		if ($condition['mode_type'] != ''){
			$condition_str .= " and mode_type = '" . $condition['mode_type'] . "'";
		}
		//排序
		if ($condition['order_by'] != ''){
			$condition_str .= " ".$condition['order_by'];
		}
		return $condition_str;
	}
	
	/**
	 * 添加缴费内容
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function addShopMode($value_array){
		if (is_array($value_array)){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				if ($v != ''){
					$valueArray[$k] = $v;
				}
			}
			$result = $GLOBALS['db']->InsertRow($valueArray,"shop_pay_mode","mode_id");
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 取缴费条目信息
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function getShopMode($id){
		if (intval($id) > 0){
			$value_array = $GLOBALS['db']->GetOneRow(intval($id),'shop_pay_mode','mode_id');
			return $value_array;
		}
		return false;
	}
	
	/**
	 * 更新缴费条目
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function updateShopMode($value_array){
		if (is_array($value_array) && intval($value_array['mode_id']) > 0){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				$valueArray[$k] = $v;
			}
			$result = $GLOBALS['db']->UpdateRow(intval($valueArray['mode_id']),$valueArray, 'shop_pay_mode', 'mode_id');
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 删除缴费条目
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function delShopMode($id){
		if (intval($id) > 0){
			$result = $GLOBALS['db']->DeleOneRow(intval($id),'shop_pay_mode','mode_id');
			return $result;
		}
		return false;
	}
	
	/**
	 * 添加会员充值明细
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function addShopPayDetail($value_array){
		if (is_array($value_array)){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				if ($v != ''){
					$valueArray[$k] = $v;
				}
			}
			$result = $GLOBALS['db']->InsertRow($valueArray,"shop_pay_detail","pay_detail_id");
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 缴费明细列表
	 * @author workflow Develop Team     
	 * @param  
	 * @return array
	 */
	function listShopPayDetail($condition,&$obj_page,$type='simple'){
		$conditionstr = $this->_conditionSearchDetail($condition);
		if ($type == 'simple'){
			$detail_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "shop_pay_detail");
		}else {//与会员表关联
			$detail_array = $GLOBALS['db']->GetJoinList($obj_page,array('shop_pay_detail','member'),"left join",array("shop_pay_detail.member_id=member.member_id"),array('*','login_name'),$conditionstr,0,array(" pay_detail_id desc"));
		}
		return $detail_array;
	}
	
	/**
	 * 构造明细检索条件
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function _conditionSearchDetail($condition){
		$condition_str = '';
		
		//提交时间
		if ($condition['date_line'] != ''){
			$condition_str .= " and shop_pay_detail.date_line = '" . $condition['date_line'] . "'";
		}
		//会员ID
		if ($condition['member_id'] != ''){
			$condition_str .= " and shop_pay_detail.member_id = '" . $condition['member_id'] . "'";
		}
		//会员名
		if ($condition['member_name'] != ''){
			$condition_str .= " and member.login_name = '" . $condition['member_name'] . "'";
		}
		//支付方式
		if ($condition['pay_name'] != ''){
			$condition_str .= " and shop_pay_detail.pay_name = '" . $condition['pay_name'] . "'";
		}
		//缴费条目ID
		if ($condition['pay_mode_id'] != ''){
			$condition_str .= " and shop_pay_detail.pay_mode_id = '" . $condition['pay_mode_id'] . "'";
		}
		//充值开始时间
		if ($condition['start_date'] != ''){
			$condition_str .= " and shop_pay_detail.date_line >= '" . $condition['start_date'] . "'";
		}
		//充值结束时间
		if ($condition['end_date'] != ''){
			$condition_str .= " and shop_pay_detail.date_line <= '" . $condition['end_date'] . "'";
		}
		
		//排序
		if ($condition['order_by'] != ''){
			$condition_str .= " ".$condition['order_by'];
		}
		
		return $condition_str;
	}
	
	/**
	 * 取缴费明细内容
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool/array
	 */
	function getShopPayDetail($id,$type='simple'){
		if (intval($id) > 0){
			if ($type == 'simple'){
				$value_array = $GLOBALS['db']->GetOneRow(intval($id),'shop_pay_detail','pay_detail_id');
			}else {
				$condition_str = " and shop_pay_detail.pay_detail_id='" . intval($id) . "'";
				//得到某会员的详细资料
				$value_array = $GLOBALS['db']->GetOneJoinArray(array('shop_pay_detail','member','member_extend'),"left join",array("shop_pay_detail.member_id=member.member_id",'shop_pay_detail.member_id=member_extend.member_id'),array('*','login_name','product_number,shop_availability_time'),$condition_str,array(" member_id desc"));
			}
			return $value_array;
		}
		return false;
	}
	
	/**
	 * 更新缴费明细
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function updateShopPayDetail($value_array){
		if (is_array($value_array) && intval($value_array['pay_detail_id']) > 0){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				$valueArray[$k] = $v;
			}
			$result = $GLOBALS['db']->UpdateRow(intval($valueArray['pay_detail_id']),$valueArray, 'shop_pay_detail', 'pay_detail_id');
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 删除缴费明细
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function delShopDetail($id){
		if (intval($id) > 0){
			$result = $GLOBALS['db']->DeleOneRow(intval($id),'shop_pay_detail','pay_detail_id');
			return $result;
		}
		return false;
	}
}
?>